/**
 * (C)2013 Exlu Corporation. All rights reserved.
 * 文件名 : cn.exlu.wea.tpk.email.EmailTransport.java
 * 注意事項   :
 */
package cn.exlu.coco.core.server.email;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;

/**
 * @author Mark 
 * @version 1.0.1
 * 2013-2-1
 * EmailTransport.java
 */
public class EmailTransport {
    private Transport transport;
    private Session session;
    
    EmailTransport(Session session,String protocol) throws MessagingException{
        this.session=session;
        transport=this.session.getTransport(protocol);
        transport.connect();
    }
    
    public void send(Email email) throws AddressException, MessagingException{
        Message message=email.createMessage(session);
        transport.sendMessage(message,message.getAllRecipients());
    }
    
    public void close() throws MessagingException{
        transport.close();
    }
}
